/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controllers;

import java.sql.SQLException;
import Models.Account;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

/**
 *
 * @author HUY
 */
public class AccountDAO {
    public ArrayList<Account> loadALL()
    {
        ArrayList<Account> listAcc = new ArrayList<Account>();
        Connection con = DBUtility.openConnection();
        PreparedStatement stm = null;
        ResultSet rs = null;
        try {
            stm = con.prepareStatement("select * from Accounts");
            rs = stm.executeQuery();
            while (rs.next()) {                
                Account acc = new Account();
                acc.setID(rs.getInt("AccID"));
                acc.setSerialNo(rs.getString("AccSerialNo"));
                listAcc.add(acc);
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }finally{
            DBUtility.closeResultSet(rs);
            DBUtility.closeStatement(stm);
            DBUtility.closeConnection(con);
        }
        return listAcc ;
    }
}
